package org.nobject.common.lang;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

public class TypeUtils {
	
	public static boolean isInterface(Type type){
		return type.toString().indexOf("interface ")==0;
	}
	
	public static boolean isClass(Type type){
		return type.toString().indexOf("class ")==0;
	}
	
	public static boolean isPremitive(Type type){
		return 
			type.toString().equals("int")
			||type.toString().equals("short")
			||type.toString().equals("long")
			||type.toString().equals("float")
			||type.toString().equals("boolean")
			||type.toString().equals("char")
			||type.toString().equals("byte")
		;
	}
	
	/** 
	 * 是否为泛型
	 * @param type
	 * @return
	 */
	public static boolean isGeneric(Type type){
		return type.toString().indexOf("<")>0;
	}
	
	public void say(List a,List<Map<String,Map<String,Map>>> l,String b,int c,Object d,List<String> e,Map<String,String[]> m){
 		
 	}
	
	public static void main(String[] args) throws Exception{
		//String s="[{nodeId:\"aaa\"}]";
		Method m=ClassUtils.getMethod(TypeUtils.class, "say");
		Class[] cps=m.getParameterTypes();
		java.lang.reflect.Type[] tps=m.getGenericParameterTypes();
		
		System.out.println(isInterface(tps[0]));
		System.out.println(isClass(tps[2]));
		System.out.println(isPremitive(tps[3]));
		System.out.println(isGeneric(tps[1]));
		
		for(Class cp:cps){
			System.out.println(cp.getName());
//			cp.getCanonicalName()
//			System.out.println(cp.get);
		}
		for(java.lang.reflect.Type type:tps){
			System.out.println(type.toString());
		}
	}
}
